<template>
  <div class="page-container">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>订单管理</span>
        </div>
      </template>

      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="orderNo" label="订单号" width="200" />
        <el-table-column prop="userName" label="用户" />
        <el-table-column prop="productName" label="商品" />
        <el-table-column prop="amount" label="金额">
          <template #default="{ row }">
            ¥{{ row.amount }}
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态">
          <template #default="{ row }">
            <el-tag :type="getStatusType(row.status)">
              {{ row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column label="操作" width="150">
          <template #default="{ row }">
            <el-button size="small" @click="handleView(row)">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        v-model:current-page="currentPage"
        :page-size="10"
        :total="50"
        layout="total, prev, pager, next"
        style="margin-top: 20px; justify-content: flex-end;"
      />
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'

const currentPage = ref(1)

const tableData = ref([
  { orderNo: 'ORD202410270001', userName: '张三', productName: 'iPhone 15 Pro', amount: 7999, status: '已完成', createTime: '2024-10-27 10:30' },
  { orderNo: 'ORD202410270002', userName: '李四', productName: 'MacBook Pro', amount: 12999, status: '待发货', createTime: '2024-10-27 11:20' },
  { orderNo: 'ORD202410270003', userName: '王五', productName: 'AirPods Pro', amount: 1999, status: '配送中', createTime: '2024-10-27 12:15' },
  { orderNo: 'ORD202410270004', userName: '赵六', productName: 'iPad Air', amount: 4799, status: '待付款', createTime: '2024-10-27 13:45' },
  { orderNo: 'ORD202410270005', userName: '钱七', productName: 'Apple Watch', amount: 2999, status: '已完成', createTime: '2024-10-27 14:30' }
])

const getStatusType = (status) => {
  const map = {
    '已完成': 'success',
    '待发货': 'warning',
    '配送中': 'primary',
    '待付款': 'info',
    '已取消': 'danger'
  }
  return map[status] || 'info'
}

const handleView = (row) => {
  ElMessage.info(`查看订单：${row.orderNo}`)
}
</script>

<style scoped>
.page-container {
  width: 100%;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
